package logic

import (
	"beike/houserpc/houserpc"
	"context"

	"beike/api/internal/svc"
	"beike/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewResAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResAddLogic {
	return &ResAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ResAddLogic) ResAdd(req *types.ResAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	resAdd, err := l.svcCtx.HouseRpc.ResAdd(l.ctx, &houserpc.ResAddRequest{
		UserId:  req.UserId,
		HouseId: req.HouseId,
		ResTime: req.ResTime,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}

	return &types.Response{
		Message: "预约成功",
		Data:    resAdd,
		Code:    200,
	}, nil
}
